<template>
  <!--委外诉讼案件-->
  <section class="page company-manage">
    <data-form :model="queryModel" :page="pageService" @handleResetForm="follFeedback" @onSearch="refreshData">
      <template slot="inputs">
        <el-form-item label="订单编号" prop="caseNumber">
          <el-input v-model="queryModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="queryModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model="queryModel.mobileNo"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="queryModel.idCard"></el-input>
        </el-form-item>
        <el-form-item label="案件金额" prop="caseMoney">
          <number-range :isInteger="true" v-model="queryModel.caseMoney"></number-range>
        </el-form-item>
        <el-form-item label="欠款金额" prop="overdueAmount">
          <number-range :isInteger="true" v-model="queryModel.overdueAmount"></number-range>
        </el-form-item>
        <el-form-item label="逾期期数" prop="overduePeriod">
          <el-select clearable placeholder="所有" v-model="queryModel.overduePeriod">
            <el-option :key="index" :label="name" :value="code.replace(/M|\+/, '')" v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="逾期天数" prop="overdueDays">
          <number-range v-model="queryModel.overdueDays"></number-range>
        </el-form-item>
        <el-form-item label="产品类型" prop="productCategory">
          <el-input v-model="queryModel.productCategory"></el-input>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="queryModel.productName"></el-input>
        </el-form-item>
        <el-form-item label="案件标签" prop="labelName">
          <get-label-name :formModel="queryModel" v-model="queryModel.labelName"></get-label-name>
        </el-form-item>
      </template>
    </data-form>
    <data-box :data="dataList" :dataList.sync="dataList" :page="pageService" :selectionList.sync="selectionList" @onPageChange="refreshData">
      <template slot="columns">
        <el-table-column :min-width="$helper.getColumnWidth(6)" label="操作">
          <template slot-scope="scope">
            <el-button @click="isView=false,lawsuitClick(scope.row)" type="text" v-auth="230" v-if="scope.row.assistStatus !== 'ASSIST_OVER'">诉讼跟进</el-button>
            <el-button @click="isView=true,lawsuitClick(scope.row)" type="text" v-auth="231" v-if="scope.row.assistStatus === 'ASSIST_OVER' && scope.row.lawerStatus && scope.row.lawsuitFollowType">跟进查看</el-button>
            <el-button @click="rowData=scope.row, dialog.isOpenCostMaintenance=true" type="text" v-auth="232">费用维护</el-button>
          </template>
        </el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(8)" label="订单编号">
          <template slot-scope="scope">
            <el-button @click="openExecutionPage(scope.row)" type="text">{{scope.row.caseNumber}}</el-button>
          </template>
        </el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="批次号" prop="batchNumber"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(3)" label="律所" prop="deptName" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(3)" label="客户名称" prop="personalName" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="手机号" prop="mobileNo" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(8)" label="身份证号" prop="idCard" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="现住址" prop="localAddress" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="案件金额(元)" prop="caseMoney"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="欠款金额(元)" prop="overdueAmount" show-overflow-tooltip></el-table-column>
        <el-table-column :formatter="row => $common.isNotValue(row.overduePeriod) ? '':`M${row.overduePeriod}`" :min-width="$helper.getColumnWidth(3)" label="逾期期数" prop="overduePeriod"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="逾期天数" prop="overdueDays" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="产品类型" prop="productCategory" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="产品名称" prop="productName" show-overflow-tooltip></el-table-column>
        <!-- <el-table-column prop="customerCategory" label="顾客类型" :min-width="$helper.getColumnWidth(4)"
                         :formatter="(row) => $filter.dictConvert(row.customerCategory, 'CustomerCategory')">
        </el-table-column>-->
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="跟进人员" prop="assistCollectorName" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(6)" label="案件创建时间" prop="createTime">
          <template slot-scope="scope">
            <span>{{scope.row.createTime | dateTimeFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column :formatter="(row) => $filter.dictConvert(row.lawerStatus,'LawerStatus')" :min-width="$helper.getColumnWidth(4)" label="诉讼状态" prop="lawerStatus" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="案件标签" prop="labelName"></el-table-column>
      </template>
    </data-box>

    <!-- 诉讼跟进-未确定诉讼类型的情况 -->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false" :visible.sync="dialog.isOpenLawsuitKind" center title="诉讼跟进">
      <lawsuit-kind :lawsuit="lawsuit" :rowData="rowData" @close="dialog.isOpenLawsuitKind = false" @refreshData="refreshData" ref="lawsuit-kind"></lawsuit-kind>
    </el-dialog>

    <!-- 诉讼跟进-已经确定诉讼类型的情况 -->
    <el-dialog :visible.sync="dialog.isOpenLawsuitFollow" @close="refreshData" @open="() => this.$nextTick(() => this.$refs['lawsuit-follow'].refresh(rowData.lawerStatus))" append-to-body center title="诉讼跟进" width="900px">
      <lawsuit-follow :isView="isView" :lawsuit="lawsuit" :rowData="rowData" @close="dialog.isOpenLawsuitFollow = false" @refreshData="refreshData" ref="lawsuit-follow"></lawsuit-follow>
    </el-dialog>

    <!-- 费用管理 -->
    <el-dialog :center="true" :visible.sync="dialog.isOpenCostMaintenance" @close="refreshData" @open="() => this.$nextTick(() => this.$refs['cost'].refreshCostData())" title="费用管理" width="1200px">
      <cost-maintain :rowData="rowData" @close="dialog.isOpenCostMaintenance = false" @refreshData="refreshData" ref="cost"></cost-maintain>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies, Layout } from "~/core/decorator";
import { OutsourceLawsuitService } from "~/services/domain-service/outsource-lawsuit-manage-index.service";
import { PageService } from "~/utils/page.service";
import { SortService } from "~/utils/sort.service";
import NumberRange from "~/components/common/number-range.vue";
import CostMaintain from "~/components/outsource-manage/outsource-lawsuit-manage/cost-maintain.vue";
import LawsuitKind from "~/components/lawsuit-follow/lawsuit-kind.vue";
import LawsuitFollow from "~/components/lawsuit-follow/lawsuit-follow.vue";
import { CASE_CHANNEL, MENU_CHANNEL } from "~/config/enum.config";
import { namespace } from "vuex-class";
import GetLabelName from "~/components/labeling-strategy/get-label-name.vue";

// @Auth(1011)
@Layout("workspace")
@Component({
  components: {
    NumberRange,
    GetLabelName,
    CostMaintain,
    LawsuitKind,
    LawsuitFollow
  }
})
export default class OutsourceLawsuitManageIndex extends Vue {
  @Dependencies(OutsourceLawsuitService)
  private outsourceLawsuitService: OutsourceLawsuitService;
  @Dependencies(PageService) private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;

  private rowData: any = {};
  private dataList: any[] = [];
  private selectionList: any[] = [];
  private isView: boolean = false;

  private get lawsuit() {
    return {
      kind: this.rowData.lawsuitFollowType,
      status: this.rowData.lawerStatus
    };
  }

  // form 查询表单参数
  private queryModel: any = {
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    idCard: "",
    overdueAmount: {
      max: "",
      min: ""
    },
    caseMoney: { min: "", max: "" },
    overduePeriod: "",
    overdueDays: {
      max: "",
      min: ""
    },
    productCategory: "",
    productName: "",
    labelName: ""
  };
  private dialog: any = {
    isOpenCostMaintenance: false,
    isOpenLawsuitKind: false,
    isOpenLawsuitFollow: false
  };

  private mounted() {
    this.refreshData();
  }

  private refreshData() {
    this.outsourceLawsuitService
      .getCaseOutLawsuitList(
        this.queryModel,
        this.pageService,
        this.sortService
      )
      .subscribe(data => (this.dataList = data));
  }

  private recycleCase() {
    if (this.selectionList.length === 0) {
      this.$message.info("请选择要回收的案件");
      return;
    }
    const ids = this.selectionList.map(v => v.id);
    this.outsourceLawsuitService.caseRecover({ ids }).subscribe(data => {
      this.$message.success(data);
      this.refreshData();
    });
  }

  /**
   * 重置numberRange
   */
  private follFeedback() {
    this.queryModel.outAmount = { min: "", max: "" };
    this.queryModel.overdueDays = { min: "", max: "" };
    this.queryModel.caseMoney = { min: "", max: "" };
  }

  /**
   * 点击诉讼跟进
   */
  private lawsuitClick(rowData) {
    this.rowData = rowData;
    if (!rowData && rowData.assistStatus === "ASSIST_OVER") {
      this.$message.info("无诉讼跟进信息");
      return;
    }
    // 如果存在诉讼类型 跳过选择诉讼类型的一步
    if (!rowData.lawsuitFollowType) {
      this.dialog.isOpenLawsuitKind = true;
    } else {
      this.dialog.isOpenLawsuitFollow = true;
    }
  }

  /**
   * 进入查看执行页
   */
  private openExecutionPage(row) {
    this.$router.openCaseDetail(row.caseId, {
      menuChannel: MENU_CHANNEL.Outsource_lawsuit,
      hiddenCaseList: true,
      hiddenAction: true
    });
  }
}
</script>

<style lang="less">
</style>


